﻿using EMall.Domain;
using System.Text.Json;

namespace EMall.IdentityService.PermissionGrants
{
    public class PermissionGrant : AggregateRoot<int>
    {
        public virtual string Permission { get; private set; }
        public virtual string Type { get; private set; }
        public virtual string Key { get; private set; }
        protected PermissionGrant() { }
        public PermissionGrant(string permission,string type,string key)
        {
            Permission = permission;
            Type = type;
            Key = key;
            AddDomainEvent(new EntityCreatedDomainEvent<PermissionGrant>(this));
        }
        public void Update(string permission, string type, string key)
        {
            var originJson = JsonSerializer.Serialize(this);
            Permission = permission;
            Type = type;
            Key = key;
            AddDomainEvent(new EntityUpdatedDomainEvent<PermissionGrant>(originJson, this));
        }
    }
}
